<template>
  <div @click="layoutFn">
    退出登录
  </div>
  <div @click="unbindFn">
    解绑微信
  </div>
</template>

<script setup lang="ts">
import { ApiUnbindingWeChat } from './api'
import toast from '@/components/toast'
import { useRouter } from 'vue-router'
import { inject } from 'vue'
import { useLoginStatus } from '@/store/loginStatus'

const { key } = inject('data') as { key: any }

const router = useRouter()
const loginStatusStore = useLoginStatus()

const layoutFn = () => {
  localStorage.removeItem('x-auth-token')
  toast({ str: '退出成功！即将跳转到首页', type: 'success' })
  setTimeout(() => {
    router.push('/home')
    key.value += 1
    loginStatusStore.changeLoginStatus(false)
  }, 1500)
}

const unbindFn = () => {
  ApiUnbindingWeChat().then((res) => {
    if (res.code === 0) {
      toast({ str: res.data!, type: 'success' })
    }
  })
}
</script>

<style lang="less" scoped>
div {
  width: 100px;
  height: 40px;
  line-height: 40px;
  background: #0a328e;
  text-align: center;
  color: #fff;
  border-radius: 5px;
  margin-bottom: 20px;
  cursor: pointer;
}
</style>
